#include <glib.h>
static void _queue_foreach_func(gpointer data, gpointer user_data)
{
    g_print("user_data:%s, data:%d \n", (gchar *)user_data, GPOINTER_TO_INT(data));
}

static gint _queue_sort_cmp_func(gconstpointer a, gconstpointer b, gpointer user_data)
{
    gint x, y;

    x = GPOINTER_TO_INT(a);
    y = GPOINTER_TO_INT(b);

    return (x > y ? +1 : x == y ? 0 : -1);
}

gint main(gint argc, gchar **argv)
{
    GQueue *q = NULL;

    q = g_queue_new();

    g_queue_push_tail(q, GINT_TO_POINTER(1));
    g_queue_push_tail(q, GINT_TO_POINTER(5));
    g_queue_push_tail(q, GINT_TO_POINTER(3));
    g_queue_push_tail(q, GINT_TO_POINTER(7));

    g_queue_foreach(q, _queue_foreach_func, "Queue-ori");

    // insert sorted
    g_queue_insert_sorted(q, GINT_TO_POINTER(6), _queue_sort_cmp_func, NULL);

    g_queue_foreach(q, _queue_foreach_func, "Queue-sort");

    g_queue_free(q);

    return 0;
}